import 'package:app/common/colors.dart';
import 'package:app/common/tool.dart';
import 'package:app/pages/sign_in_module/sign_controller.dart';
import 'package:app/services/address.dart';
import 'package:app/services/dio_manager.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:graphic/graphic.dart';

import '../../common/app_theme.dart';
import 'attendance_model.dart';

class AttendanceRecordView extends GetView{



  SignController controller = Get.put(SignController());



  List<Figure> centralPieLabel(
      Size size,
      Offset anchor,
      Map<int, Tuple> selectedTuples,
      ) {
    final tuple = selectedTuples.values.last;

    final titleSpan = TextSpan(
      text: '${tuple['genre']}\n',
      style: const TextStyle(
        fontSize: 14,
        color: Colors.black87,
      ),
    );

    final valueSpan = TextSpan(
      text: tuple['sold'].toString(),
      style: const TextStyle(
        fontSize: 20,
        color: Colors.black87,
      ),
    );

    final painter = TextPainter(
      text: TextSpan(children: [titleSpan, valueSpan]),
      textDirection: TextDirection.ltr,
      textAlign: TextAlign.center,
    );
    painter.layout();

    final paintPoint = getPaintPoint(
      const Offset(50, 50),
      painter.width,
      painter.height,
      Alignment.center,
    );

    return [TextFigure(painter, paintPoint)];
  }





  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: PreferredSize(
        preferredSize: Size(Get.width, AppTool.appBarHEIGHT),
        child: AppBar(
          title: Text('出勤情况',style: TextStyle(color: Colors.black),),
        ),
      ),
      body: GetBuilder<SignController>(builder: (_){
        return ListView(
          children: [
            Container(
              color: Colors.white,
              margin: const EdgeInsets.only(top: 10),
              width: 350,
              height: 300,
              child: Chart(
                data: controller.basicData,
                variables: {
                  'genre': Variable(
                    accessor: (Map map) => map['genre'] as String,
                  ),
                  'sold': Variable(
                    accessor: (Map map) => map['sold'] as num,
                  ),
                },
                transforms: [
                  Proportion(
                    variable: 'sold',
                    as: 'percent',
                  )
                ],
                elements: [
                  IntervalElement(
                    position: Varset('percent') / Varset('genre'),
                    color: ColorAttr(
                        variable: 'genre', values: Defaults.colors10),
                    modifiers: [StackModifier()],
                  )
                ],
                coord: PolarCoord(
                  transposed: true,
                  dimCount: 1,
                  startRadius: 0.5,
                ),
                selections: {'tap': PointSelection()},
                tooltip: TooltipGuide(renderer: centralPieLabel),
              ),
            ),

            Container(
              height: 50,
              color: Colors.white,
              child: Row(
                children: [
                  Expanded(child: Container(
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Text('${controller.model?.data?.attendDays}',style:TextStyle(color: AppColor.themeColor,fontWeight: FontWeight.w700),),
                        Text('出勤（天）',style: appThemeData.textTheme.bodyText1,)
                      ],
                    ),
                  ),flex: 1,),
                  Expanded(child: Container(
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Text('${controller.model?.data?.notAttendDays}',style:TextStyle(color: Color(0xff5ad8a6),fontWeight: FontWeight.w700),),
                        Text('未出勤（天）',style: appThemeData.textTheme.bodyText1,)
                      ],
                    ),
                  ),flex: 1,),

                ],
              ),
            ),
            Container(
              margin: EdgeInsets.only(top: 10),
              padding: EdgeInsets.only(left: 15,top: 5,right: 15),
              color: Colors.white,
              height: 100,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text('出勤情况汇总'),
                  SizedBox(height: 15,),
                  Container(
                    height: 50,
                    color: Colors.white,
                    child: Row(
                      children: [
                        Expanded(child: Container(
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Text('${controller.model?.data?.totalDay}',style:TextStyle(fontWeight: FontWeight.w700),),
                              Text('总天数',style: appThemeData.textTheme.subtitle1,)
                            ],
                          ),
                        ),flex: 1,),
                        Expanded(child: Container(
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Text('${controller.model?.data?.notAttendDays}',style:TextStyle(fontWeight: FontWeight.w700),),
                              Text('总考勤天数',style: appThemeData.textTheme.subtitle1,)
                            ],
                          ),
                        ),flex: 1,),
                        Expanded(child: Container(
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Text('${controller.model?.data?.attendDays}',style:TextStyle(fontWeight: FontWeight.w700),),
                              Text('出勤天数',style: appThemeData.textTheme.subtitle1,)
                            ],
                          ),
                        ),flex: 1,),
                        Expanded(child: Container(
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Text('${controller.model?.data?.notAttendDays}',style:TextStyle(fontWeight: FontWeight.w700),),
                              Text('未出勤天数',style: appThemeData.textTheme.subtitle1,)
                            ],
                          ),
                        ),flex: 1,),
                        Expanded(child: Container(
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Text('${controller.model?.data?.notCheckOut}',style:TextStyle(fontWeight: FontWeight.w700),),
                              Text('未签到天数',style: appThemeData.textTheme.subtitle1,)
                            ],
                          ),
                        ),flex: 1,),

                      ],
                    ),
                  ),
                ],
              ),
            ),

            Container(
              margin: EdgeInsets.only(top: 10),
              padding: EdgeInsets.only(left: 15,top: 5),
              color: Colors.white,
              height: 100,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text('请假信息'),
                  SizedBox(height: 15,),
                  Center(
                    child: Text('暂无请假信息',style: appThemeData.textTheme.subtitle1,),
                  )
                ],
              ),
            ),

            Container(
              margin: EdgeInsets.only(top: 10),
              padding: EdgeInsets.only(left: 15,top: 5),
              color: Colors.white,
              height: 100,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text('外勤'),
                  SizedBox(height: 15,),
                  Center(
                    child: Text('暂无外勤信息',style: appThemeData.textTheme.subtitle1,),
                  )
                ],
              ),
            ),
            SizedBox(height: 100,),
          ],
        );
      }),
    );
  }

}